/**
 * ClassNameUtilities.java
 * @author: liuex
 * 2008-1-8 ����05:25:45
 *
 * note: 
 */
package org.lex.reflect.browsing.util;

import java.util.ArrayList;
import java.util.StringTokenizer;

public class ClassNameUtilities {
	public static boolean isArchiveFileName(String name) {
		name = name.toLowerCase();
		return (name.endsWith(".jar") || name.endsWith(".zip"));
	}

	public static boolean isClassFileName(String name) {
		int index = name.lastIndexOf('.');
		if (-1 == index || -1 != name.indexOf('$')) {
			return false;
		} else {
			String extName = name.substring(index);
			return extName.equalsIgnoreCase(".class");
		}
	}

	/**
	 * Create a proper class name from a messy thing. Turn / or \ into ., remove
	 * leading class and trailing .class Note: this makes lots of strings...
	 * could be faster.
	 */
	public static String canonicalizeClassName(String name) {
		String classname = name.replace('/', '.');
		classname = classname.replace('\\', '.');
		if (classname.startsWith("class "))
			classname = classname.substring(6);
		if (classname.endsWith(".class"))
			classname = classname.substring(0, classname.length() - 6);
		return classname;
	}

	public static String[] split(String s, String delim) {
		ArrayList<String> tokens = new ArrayList<String>();
		StringTokenizer st = new StringTokenizer(s, delim);
		while (st.hasMoreTokens())
			tokens.add(st.nextToken());
		return tokens.toArray(new String[tokens.size()]);
	}
}
